﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StudentApartMentManage
{
    public partial class AddAdmin : Form
    {
        public AddAdmin()
        {
            InitializeComponent();
        }

        private void AddAdmin_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = sqlHelper.GetTable("select 管理员ID,密码,姓名,性别,联系方式,职务 from 公寓管理员信息表");

        }

        private void button2_Click(object sender, EventArgs e)
        {
            if(MessageBox.Show("你这的要清空输入的信息吗?","警告",MessageBoxButtons.YesNo)==DialogResult.Yes)
            {
                textBox1.Clear();
                textBox2.Clear();
                textBox3.Clear();
                textBox4.Clear();
                radioButton1.Checked = true;
                comboBox1.Text = "";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(textBox1.Text.Length==0)
            {
                MessageBox.Show("管理员ID不可为空!");
                return;
            }
            try
            {
                if(MessageBox.Show("你真的要添加管理员的信息吗?","提示",MessageBoxButtons.YesNo)==DialogResult.Yes)
                {
                    string sql = string.Format("insert into 公寓管理员信息表(管理员ID,密码,姓名,性别,职务,管理员级别) values('{0}','{1}','{2}','{3}','{4}','{5}')", textBox1.Text.Trim(), textBox2.Text.Trim(), textBox3.Text.Trim(), radioButton1.Checked ? "男" : "女", textBox4.Text.Trim(), comboBox1.Text.Trim());
                    int i = sqlHelper.Execute(sql);
                    if(i!=-1)
                    {
                        MessageBox.Show("添加管理员信息成功!");
                    }else
                    {
                        MessageBox.Show("添加管理员信息失败!");
                    }
                    dataGridView1.DataSource = sqlHelper.GetTable("select 管理员ID,密码,姓名,性别,联系方式,职务 from 公寓管理员信息表");
                    return;
                }
           
            }
            catch (Exception ex)
            {
                MessageBox.Show("添加失败!");
                return;
            }
        }
    }
}
